import { BoolOperation, Expression, Operator } from './types';
import { reverse } from './not';
import { simplify } from './simplify';

/**
 * 求差集
 */
export function diff(expA: Expression, expB: Expression): Expression  {
  const reversedExpB = reverse(expB);
  if (reversedExpB.operator === Operator.EMPTY) {
    return expA;
  }

  return simplify({
    operator: BoolOperation.AND,
    args: [expA, reversedExpB],
  });
}
